Skip to main content

Garbage Collector

Garbage Collector (GC) in iRidi is a built-in background memory manager. It runs in the server software of iRidi Pro and i3 Pro. The collector frees RAM from objects the program no longer uses, above all JavaScript objects. This lowers the risk of memory leaks and of the automation server slowing down.

What it does​

Project server logic in iRidi runs on JavaScript (ECMAScript). Scripts create objects, variables, and functions, and all of that uses memory. When nothing points at an object, it becomes unreachable, but the memory is released only after a collector pass. Without the collector, the server can eventually run out of available RAM and stop answering requests or running scenarios.

Stability and responsiveness depend on the collector. The faster a cleanup finishes, the rarer the pauses while commands are handled, and the longer the server keeps working steadily.

Important

Frequent or long Garbage Collector runs are not a separate fault. They are a symptom. They show that the project's JavaScript is putting too much pressure on memory. The system can then slow down and stall while it handles commands.

If the collector runs often​

The collector starts too often because the code keeps creating many short-lived objects. That happens with inefficient loops, frequent temporary variables, heavy event handling, and inefficient work with data.

  1. Check the hot parts of the code. Find the scripts that run most often: event handlers and periodic tasks. Those are the most likely to create extra garbage.
  2. Replace setInterval with a recursive setTimeout. On an iRidi server this matters. setInterval can start the next call before the previous one finishes. Calls overlap and objects pile up. A recursive setTimeout starts the next iteration only after the current one has fully finished.
  3. Do not create objects inside functions that are called often. Keep constants and reusable structures outside the function so they are not created again on every call.
  4. Use native iRidi drivers and functions where you can. Built-in platform tools are usually more stable than custom scripts and do not create some of the garbage that hand-written code would.

If the collector runs for a long time​

A single collection pass takes a long time. That usually means there are too many live objects in memory: the collector spends a long time walking the reference graph and deciding what can be deleted. The cause can be deeper than a large amount of garbage: memory leaks, where objects stay reachable although they are no longer needed; too much data held in memory at once; or an inefficient project architecture.

  1. Look for memory leaks. Check forgotten references. Typical causes: an event subscription without removeEventListener, closures that keep large objects, and global variables that accumulate data and are never cleared.
  2. Estimate how much data is in memory. Large arrays, event history, and a rarely used cache increase the live set and the collector runtime. Some data can be written to disk or cleared on a schedule.
  3. Simplify the project logic. Extra automations, schedules, and long script chains increase the number of objects that must stay in memory. Reviewing the logic lowers the baseline load.
  4. Split the project if code changes are not enough. Long runs after code fixes can mean the project is too large for one server. Some functions, such as separate subsystems or drivers, can be moved to a second iRidi Pro server.

Rate and Time​

Garbage Collector Rate is the number of runs in 24 hours. Garbage Collector Time is the total time the collector ran over that same period. These are diagnostic readings, not strict KPIs. Read them together with the project complexity and the overall server load.

Rough ranges​

ParameterRoughly normal rangeExample of normalExample of too high
Garbage Collector Rate, runs per 24 hFrom a few runs to a few dozenA simple project, such as apartment lighting and a few dozen tags: 5–20 runs per day. The code runs rarely and creates little garbageA complex project with intensive logic: hundreds of runs per day. If Rate is above 200–300, the code creates too many short-lived objects and the system keeps spending resources on cleanup
Garbage Collector Time, total time per 24 hFrom a few seconds to a few minutesA stable system: over a day the collector runs for a few seconds or minutes. Each pass is short and memory is not full of live objectsA troubled project: over a day the collector runs for tens of minutes or hours. If Time is above 30–60 minutes, memory leaks or a very large data set are likely, and the collector takes a long time to walk it

How to read the readings​

The warning sign is not a high value by itself, but a high value together with the system slowing down.

  • High Rate and low Time. The collector starts often, but each pass is short. The code creates many temporary objects, and a critical slowdown may not have appeared yet. There is a reason to optimize the code and reduce CPU load.
  • Any Rate and an abnormally high Time. This is more serious: the collector has to walk a large amount of live data. That is often a memory leak or inefficient storage in RAM. Noticeable pauses appear while commands run.

If the readings leave the rough normal range and the iRidi server has become slower or less responsive, review the JavaScript and the project architecture.